#include "Vector3.h"

SGF::Vector3::Vector3()
{
	_x = 0;
	_y = 0;
	_z = 0;
}

SGF::Vector3::Vector3( Real64 x, Real64 y, Real64 z )
{
	_x = x;
	_y = y;
	_z = z;
}

SGF::Vector3::Vector3( const Vector3& src )
{
	_x = src._x;
	_y = src._y;
	_z = src._z;
}
SGF::Vector3& SGF::Vector3::operator=( const Vector3& src )
{
	_x = src._x;
	_y = src._y;
	_z = src._z;
	return* this;
}

SGF::Real64 SGF::Vector3::operator*( const Vector3& src )
{
	return _x * src._x + _y * src._y + _z * src._z;
}

SGF::Vector3& SGF::Vector3::operator+=( const Vector3& src )
{
	_x += src._x;
	_y += src._y;
	_z += src._z;
	return* this;
}

SGF::Vector3& SGF::Vector3::operator-=( const Vector3& src )
{
	_x -= src._x;
	_y -= src._y;
	_z -= src._z;
	return* this;
}

SGF::Vector3 SGF::Vector3::operator+( const Vector3& src )
{
	return Vector3(_x + src._x, _y + src._y, _z + src._z);
}

SGF::Vector3 SGF::Vector3::operator-( const Vector3& src )
{
	return Vector3(_x - src._x, _y - src._y, _z - src._z);
}

SGF::Real64& SGF::Vector3::operator[]( int index )
{
	switch (index)
	{
	case 0:
		return _x;
	case 1:
		return _y;
	case 2:
		return _z;
	default:
		throw 10;
	}
}

SGF::Vector3 SGF::Vector3::CrossProduct( const Vector3& src1, const Vector3& src2 )
{
	return Vector3(src1._y * src2._z - src1._z * src2._y,
			   	   src1._z * src2._x - src1._x * src2._z,
				   src1._x * src2._y - src1._y * src2._x);
}

SGF::Real64 SGF::Vector3::Length( const Vector3& src )
{
	return Math<Real64>::Sqrt(src._x * src._x + src._y * src._y + src._z * src._z);
}

SGF::Vector3 SGF::Vector3::Normalize( const Vector3& src )
{
	Real64 len = Math<Real64>::Sqrt(src._x * src._x + src._y * src._y + src._z * src._z);
	return Vector3(src._x / len, src._y / len, src._z / len);
}

std::ostream& SGF::operator<<( std::ostream& stream, const Vector3& src )
{
	stream << "(" << src._x << "," << src._y << "," << src._z << ")";
	return stream;
}